package com.itheima.module.web.controller.restful;


import com.itheima.module.pojo.User;
import com.itheima.module.web.vo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController

public class RestFulController {

    //@RequestMapping("/add")
    //@RequestMapping(value="/user",method = RequestMethod.POST)
    @PostMapping("/user")
    public String addUser(@RequestBody User user){

        System.out.println("新增用户逻辑:"+user);
        return "success";
    }
    //@RequestMapping("/user/findById")
    //@RequestMapping(value="/user/{id}",method = RequestMethod.GET)
    @GetMapping("/user/{id}")
    public Result findById(@PathVariable("id") int id){
        System.out.println("查询id为:"+id+"的用户");

        int i=5/0;

        return Result.successOf("正常数据 查询用户模拟!!!");
    }

    //@RequestMapping("/user/updateUser")
    //@RequestMapping(value="/user",method = RequestMethod.PUT)
    @PutMapping("/user")
    public String updateUser(@RequestBody User user){
        System.out.println("更新数据:"+user);
        return "success";
    }
    @DeleteMapping("/user/{id}")
    public String deleteById(@PathVariable("id") int id){

        System.out.println("删除id 为:"+id+" 的用户");
        return "success";
    }

    /**
     *  根据 用户名或者邮箱查询用户
     *  _search
     */

    @GetMapping("/user/_search")
    //@GetMapping("/user/findByCondition")
    public String deleteById(
            @RequestParam("email")String email,
            @RequestParam("username")String username){

        System.out.println("查询用户下子资源");
        return "success";
    }

    @GetMapping("/user/register")
    //@GetMapping("/user/findByCondition")
    public String register(
            @RequestParam("email")String email,
            @RequestParam("username")String username){

        System.out.println("查询用户下子资源");
        return "success";
    }



}
